package com.zhx.real.security.handler;

import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * describe: 默认的 操作拦截处理
 *
 * @author zhanghaixuan
 * @date 2018/08/21
 **/
public class DefaultCuestomAccessDeniedHandler implements CuestomAccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setStatus(HttpStatus.FORBIDDEN.value());
        response.setContentType("application/json,charset=UTF-8");
        String message = "无权限执行当前操作";
        response.getWriter().write("\"" + message + "\"");
    }
}
